﻿
#region Usings

using FasterWPF;
using FasterWPFDemo.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using wpfToolkit = Xceed.Wpf.Toolkit;
using FasterWPFExtras;
using System.ComponentModel;
using System.Windows.Markup;
using System.Collections;
using System.Windows.Controls.Primitives;
using FasterWPF.Generators;
#endregion

namespace FasterWPFDemo
{
    public partial class TabItem01 : UserControl, IUserControlGuid
    {
        private string _userCtlGuid = null;

        public string UserControlGuid
        {
            get
            {
                return _userCtlGuid;
            }

            set
            {
                _userCtlGuid = value;
            }
        }

        #region Class-Level Variables

        string twoGUID = null;
        ListBox myListBox = null;
        ListView myListView = null;
        Border thisComposite = null;
        AdornerDecorator ad = null;
        List<Tuple<int, string, int>> tList;
        bool isLoading = false;
        #endregion

        public TabItem01()
        {
            //InitializeComponent(); XAML removed. Initialize via code-behind.

            this.Initialize(ContainerType.VerticalPanel);

            //this.Width = 750D;
            //this.Height = 550D;          

            this.BeginSettings<UserControl>().SetItemBorderColorAndThickness<UserControl>(Brushes.Gray, new Thickness(0))
                .SetSelectorClass<UserControl>(0, 0, "tabLabel")
                .SetFontOnLabel<UserControl>(0, 0, "Segoe UI", 12D, FontWeights.Normal, FontStyles.Normal)
                .SetTextColorForLabel<UserControl>(0, 0, Brushes.White)
                .EndSettings();
        }

        public void LoadUserControl()
        {          
            Grid myGrid = null;
            myGrid = new Grid();
            myListBox = new ListBox();
            myListView = new ListView();
            DockPanel myDockPanel2 = null;
            DockPanel myDockPanel3 = null;
            Border flatButton = null;
            Border flatButton2 = null;
            myListBox.Name = "myListBox";
            myListView.Name = "myListView";
            myDockPanel2 = new DockPanel();
            myDockPanel3 = new DockPanel();
            isLoading = true;

            //You would want to null these out on disposing this TabItem1 to prevent these references from keeping this TabItem1 alive
            Canvas cnvs = Application.Current.Properties["Canvas"] as Canvas;
            Border brd1 = Application.Current.Properties["Dialog"] as Border;            
            String cnvsguid0 = Application.Current.Properties["CanvasGuid0"] as String;
            ad = Application.Current.Properties["AdornerDecorator"] as AdornerDecorator;

            GlobalStoreService.PutInGlobalStore(GlobalStoreService.TabControlGuids.One, "CoreControlFull1", myGrid);
            GlobalStoreService.PutInGlobalStore(GlobalStoreService.TabControlGuids.One, "MyListBox", myListBox);
            GlobalStoreService.PutInGlobalStore(GlobalStoreService.TabControlGuids.One, "MyListView", myListView);

            string cbGuid1 = Guid.NewGuid().ToString();
            string cbGuid2 = Guid.NewGuid().ToString();
            string cbGuid3 = Guid.NewGuid().ToString();
            string cbGuid4 = Guid.NewGuid().ToString();
            string cbGuid5 = Guid.NewGuid().ToString();
            string cbGuid6 = Guid.NewGuid().ToString();
            string cbGuid7 = Guid.NewGuid().ToString();
            string cbGuid8 = Guid.NewGuid().ToString();
            string cbGuid9 = Guid.NewGuid().ToString();            
            string gridguid2 = Guid.NewGuid().ToString();
            string gridguid3 = Guid.NewGuid().ToString();
  
            #region Setup Grid

             myGrid.Background = Brushes.WhiteSmoke;
             myGrid.Initialize(double.NaN, double.NaN, 27D, ContainerType.Grid, 2, 3, 0.33, GridUnitType.Star, 0.5D, GridUnitType.Star);
             myGrid.SetCompositeGridDimensions<Grid>(17, 4, 0.33, GridUnitType.Auto, 100, GridUnitType.Auto);

             myGrid.ShowGridLines = true;
         
             string gridguid1 = null;
             gridguid1 = Guid.NewGuid().ToString();

             myGrid.BeginSettings<Grid>()
            .SetSelectorClass<Grid>(0, 0, "mainLabels")
            .SetBackgroundColor<Grid>(Brushes.White)
            .SetUseLayoutRounding<Grid>(true)
            .SetFontOnLabel(0, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFontOnLabel(1, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(2, 1, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(3, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(4, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(5, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(12, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(14, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(15, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(16, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(5, 3, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetFont(8, 3, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .SetTextBackground(0, 0, Brushes.Aqua)
            .SetHorizontalAlignmentForText<Grid>(1, 1, TextAlignment.Center)
            .SetHorizontalAlignmentForText<Grid>(2, 1, TextAlignment.Center)
            .SetTextEffect<Grid>(0, 0, new System.Windows.Media.Effects.DropShadowEffect())
            .Set<CheckBox, Grid>("Content", "Hello World")
            .Set<TextBox, Grid>("MaxHeight", 30D)
            .Set<TextBox, Grid>(1, 1, "Text", "Lake Michigan")
            .Set<TextBox, Grid>(2, 1, "Text", "Chicago, Illinois")
            .Set<TextBox, Grid>("Margin", new Thickness(1, 3, 1, 3))
            .Set<ListBox, Grid>("Margin", new Thickness(1, 1, 1, 1))
            .SetVerticalAlignment<Grid>(2, 1, VerticalAlignment.Bottom)
            .SetVerticalAlignment<Grid>(3, 1, VerticalAlignment.Top)
            .SetAttachedProperty<Label, Grid>(
        "ColumnSpan", 0, 0, obj => { obj.SetValue(Grid.ColumnSpanProperty, 2); })
            //.Set<Label, Grid>("Content", "Add a New Vacation")
           // .Set<Label, Grid>("HorizontalContentAlignment", HorizontalAlignment.Left)
            .Set<Label, Grid>("Background", Brushes.GhostWhite)
            .SetVerticalAlignment<Grid>(0, 0, VerticalAlignment.Center)
            .SetHorizontalAlignmentForText<Grid>(0, 0, TextAlignment.Center)
            .SetHorizontalAlignmentForLabel<Grid>(1, 0, HorizontalAlignment.Right)
            .SetHorizontalAlignmentForText<Grid>(3, 0, TextAlignment.Right)
            .SetHorizontalAlignmentForText<Grid>(4, 0, TextAlignment.Right)
            .SetHorizontalAlignmentForText<Grid>(5, 0, TextAlignment.Right)
            .SetHorizontalAlignmentForText<Grid>(15, 0, TextAlignment.Right)
            .SetTextPadding<Grid>(15, 0, new Thickness(4))
            .SetTextPadding<Grid>(12, 0, new Thickness(7))
            .SetVerticalAlignment<Grid>(1, 0, VerticalAlignment.Center)
            .SetVerticalAlignment<Grid>(1, 1, VerticalAlignment.Center)
            .SetTextPadding<Grid>(1, 0, new Thickness(7))
            .SetHorizontalAlignmentForText<Grid>(2, 0, TextAlignment.Right)
            .SetVerticalAlignment<Grid>(2, 0, VerticalAlignment.Center)
            .SetVerticalAlignment<Grid>(3, 0, VerticalAlignment.Center)
            .SetVerticalAlignment<Grid>(4, 0, VerticalAlignment.Center)
            .SetVerticalAlignment<Grid>(5, 0, VerticalAlignment.Center)
            .SetVerticalAlignment<Grid>(5, 3, VerticalAlignment.Center)
            .SetVerticalAlignment<Grid>(8, 3, VerticalAlignment.Center)
            .SetTextPadding<Grid>(2, 0, new Thickness(7))
            .SetTextPadding<Grid>(3, 0, new Thickness(7))
            .SetTextPadding<Grid>(4, 0, new Thickness(7))
            .SetTextPadding<Grid>(5, 0, new Thickness(7))
            .SetTextPadding<Grid>(8, 3, new Thickness(3, 0, 0, 0))
            .SetFont(2, 0, "Arial", 11, FontWeights.Bold, FontStyles.Normal)
            .Set<wpfToolkit.MultiLineTextEditor, Grid>("Width", 57D)
            .SetAttachedProperty<TextBox, Grid>("RowSpan", 11, 3, txtBox => { txtBox.SetValue(Grid.RowSpanProperty, 4); })
            .SetAttachedProperty<TextBlock, Grid>("ColSpan", 15, 0, txtBlk => { txtBlk.SetValue(Grid.ColumnSpanProperty, 2); })
            .SetHorizontalAlignmentForText<Grid>(12, 0, TextAlignment.Right)
            .SetHorizontalAlignmentForText<Grid>(14, 0, TextAlignment.Right)
            .SetItemBorderColorAndThickness(Brushes.Blue, new Thickness(0))
            .EndSettings<Grid>();

            myGrid.SetTextPadding<Grid>(14, 0, new Thickness(7)); //You don't have to do settings within BeginSettings . . . EndSettings
                      
            //myGrid.SubscribeMouseDoubleClick(new MouseButtonEventHandler(my_MouseDoubleClick));

            #endregion
            
            #region Setup Button for Test Sorting of Grid and ListBox
            string borderButton0Guid = Guid.NewGuid().ToString();

            Border borderButton0 = new Border();
            borderButton0.MaxHeight = 50;
            
            borderButton0.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, Brushes.Indigo, new Thickness(2), Brushes.PowderBlue, new CornerRadius(10), new Thickness(0), new Thickness(1));
            borderButton0.BeginSettings<Border>()
                .SubscribeDependencyEventOnParent("IsEnabledChanged", (ve =>
                {
                    //mimmick something like the Visual State Manager
                    if (borderButton0.IsEnabled == false)
                    {
                        //typically just unsubscribe, change colors to grey and then re-subscribe
                        //but if you need to remove and re-add a composite, clear the singleclick event settings too via bool=true
                        borderButton0.UnsubscribeMouseSingleClickOnBorderAll(true);
                        
                        string transferData0_0 = borderButton0
                            .GetCompositeFromParent(borderButton0Guid)
                            .GetChildFromComposite<TextBlock, Border>(0, 0).GetText();

                        if (borderButton0.IsCompositeOnParent(borderButton0Guid))
                        {
                            borderButton0.RemoveByKey(borderButton0Guid);
                        }

                        BorderExt.ChangeBackgroundColor(borderButton0, Brushes.Gray);

                        //transfer data so as to maintain data from prior composite
                        borderButton0.BeginComposite(borderButton0Guid)
                          .AddText<Border>(0, 0, transferData0_0)
                          .EndComposite<Border, BorderArgs>(null);
                    }
                    else
                    {
                        string transferData0_0 = borderButton0
                            .GetCompositeFromParent(borderButton0Guid)
                            .GetChildFromComposite<TextBlock, Border>(0, 0).GetText();

                        if (borderButton0.IsCompositeOnParent(borderButton0Guid))
                        {
                            borderButton0.RemoveByKey(borderButton0Guid);
                        }

                        BorderExt.ChangeBackgroundColor(borderButton0, Brushes.PowderBlue); //restore original color
                        createEnabledButtonComposite(myGrid, borderButton0Guid, borderButton0, transferData0_0);
                    }

                } ))
                .SetTextPadding<Border>(0, 0, new Thickness(4)).EndSettings<Border>();

            createEnabledButtonComposite(myGrid, borderButton0Guid, borderButton0, null);
               
            borderButton0.IsEnabled = false;
                      

            Border borderButton1 = new Border();
            borderButton1.MaxHeight = 50;
            borderButton1.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, Brushes.Indigo, new Thickness(2), Brushes.PowderBlue, new CornerRadius(10), new Thickness(0), new Thickness(1));
            borderButton1.BeginSettings<Border>().SetTextPadding<Border>(0, 0, new Thickness(4)).EndSettings<Border>();

            IDisposable dispB1 = null;
            borderButton1.SubscribeMouseSingleClickOnBorder<Border>((o, ev) =>
            {
                //re-enable the other button
                borderButton0.IsEnabled = true;

                //in lieu of Color Animation, consider Rx . . .
                BorderExt.ChangeBackgroundColor(borderButton1, Brushes.Khaki);
                BorderExt.SetMouseOverColorOnBorder(borderButton1, Brushes.Khaki);

                //Display Khaki for 3 seconds, then revert to PowderBlue
                dispB1 = Observable.Timer(TimeSpan.FromSeconds(3)).Subscribe(t =>
                {
                    Dispatcher.RunInUiThread(() =>
                    {

                        BorderExt.ChangeBackgroundColor(borderButton1, Brushes.PowderBlue);
                        BorderExt.SetMouseOverColorOnBorder(borderButton1, Brushes.Orange);
                    });
                });

                GridSort gs = new GridSort(FasterWPF.CommonExt.SortDataType.DateTime);
                myGrid.SortByText<Grid>(gs, 0, 0, CommonExt.SortOrder.Desc, CommonExt.SortControlType.Label);

            });

            borderButton1.SetMouseOverColorOnBorder(Brushes.Orange);

            borderButton1.BeginComposite()
                .AddText<Border>(0, 0, "Sort Grid by Date Desc 1")
                .EndComposite<Border, BorderArgs>(null);

            Border borderButton = new Border();
            borderButton.MaxHeight = 50;
            borderButton.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, Brushes.Indigo, new Thickness(2), Brushes.PowderBlue, new CornerRadius(10), new Thickness(0), new Thickness(1));
            borderButton.BeginSettings<Border>().SetTextPadding<Border>(0, 0, new Thickness(4)).EndSettings<Border>();

            borderButton.SubscribeMouseSingleClickOnBorder<Border>((o, ev) =>
            {
                //disable other button runs . . .
                borderButton0.IsEnabled = false;

                //in lieu of Color Animation, consider Rx . . .
                BorderExt.ChangeBackgroundColor(borderButton, Brushes.Khaki);
                BorderExt.SetMouseOverColorOnBorder(borderButton, Brushes.Khaki);

                //Display Khaki for 5 seconds, then revert to PowderBlue
                this.WaitForXSeconds(5, ()=>{

                        BorderExt.ChangeBackgroundColor(borderButton, Brushes.PowderBlue);
                        BorderExt.SetMouseOverColorOnBorder(borderButton, Brushes.Orange);
                    });

                b_Click(o, ev);

            });

            borderButton.SetMouseOverColorOnBorder(Brushes.Orange);

            borderButton.BeginComposite()
                .AddText<Border>(0, 0, "Test Sorting of ListBox")
                .EndComposite<Border, BorderArgs>(null);

            #endregion

            #region Setup Button for Field Validation

            Border validateButton = new Border();
            validateButton.MaxHeight = 50;
            validateButton.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, Brushes.Indigo, new Thickness(2), Brushes.PowderBlue, new CornerRadius(10), new Thickness(0), new Thickness(1));
            validateButton.BeginSettings<Border>().SetTextPadding<Border>(0, 0, new Thickness(4)).EndSettings<Border>();

            validateButton.SubscribeMouseSingleClickOnBorder<Border>( validateButton_ValidateFields );

            validateButton.SetMouseOverColorOnBorder(Brushes.Orange);
            validateButton.BeginComposite()
                .AddText<Border>(0, 0, "Validate TextBoxes")
                .EndComposite<Border, BorderArgs>(null);

            #endregion

            #region Setup Buttons for Open and Close Dialog

            flatButton = new Border();
            flatButton2 = new Border();
            List<Border> flatButtons = new List<Border>();
            flatButtons.Add(flatButton);
            flatButtons.Add(flatButton2);

            flatButton.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, Brushes.Indigo, new Thickness(2), Brushes.PowderBlue, new CornerRadius(10), new Thickness(0), new Thickness(3));
            flatButton.BeginSettings<Border>().SetTextPadding<Border>(0, 0, new Thickness(4)).EndSettings<Border>();

            flatButton.SubscribeMouseSingleClickOnBorder<Border>((o, ev) =>
            {
                //CLOSE DIALOG
                //IDisposable dispDialogTimer = null;
                if (cnvs.IsCompositeOnParent<Canvas>(cnvsguid0))
                {
                    cnvs.GetCompositeFromParent<Canvas>(cnvsguid0).FadeOut(.5);
                    cnvs.GetCompositeFromParent<Canvas>(cnvsguid0).DoubleAnimate(Canvas.LeftProperty, 330D, 0D, TimeSpan.FromSeconds(.5), false, false);

                    Dispatcher.WaitFor(TimeSpan.FromSeconds(.5), () =>
                    {
                        cnvs.RemoveByKey<Canvas>(cnvsguid0);
                    });

                }
                BorderExt.ChangeBackgroundColor(flatButtons[0], Brushes.Khaki);
                BorderExt.ChangeBackgroundColor(flatButtons[1], Brushes.PowderBlue);
            });

            flatButton.SetMouseOverColorOnBorder(Brushes.Orange);
            string myBorderGuid90 = Guid.NewGuid().ToString();
            flatButton.BeginComposite(myBorderGuid90).AddText<Border>(0, 0, "Close Dialog").EndComposite<Border, BorderArgs>(null);

            flatButton2.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, Brushes.Indigo, new Thickness(2), Brushes.PowderBlue, new CornerRadius(10), new Thickness(0), new Thickness(3));
            flatButton2.BeginSettings<Border>().SetTextPadding<Border>(0, 0, new Thickness(4)).EndSettings<Border>();

            flatButton2.SubscribeMouseSingleClickOnBorder<Border>((o, ev) =>
            {
                //OPEN DIALOG
                if (!cnvs.IsCompositeOnParent<Canvas>(cnvsguid0))
                {
                    Border myOpenDialog = cnvs.BeginComposite(cnvsguid0)
                     .AddExisting<Border, Canvas>(0, 0, brd1)
                     .EndComposite<Canvas, CanvasArgs>(new CanvasArgs(0D, 330D, 500));

                    myOpenDialog.FadeIn(.5);
                    myOpenDialog.DoubleAnimate(Canvas.LeftProperty, 0D, 330D, TimeSpan.FromSeconds(.5), false, false);

                }

                BorderExt.ChangeBackgroundColor(flatButtons[1], Brushes.Khaki);
                BorderExt.ChangeBackgroundColor(flatButtons[0], Brushes.PowderBlue);
            });

            flatButton2.SetMouseOverColorOnBorder(Brushes.Orange);

            string myBorderGuid1 = Guid.NewGuid().ToString();
            flatButton2.BeginComposite(myBorderGuid1).AddText<Border>(0, 0, "Open Dialog").EndComposite<Border, BorderArgs>(null);

            //CLOSE DIALOG
            if (cnvs.IsCompositeOnParent<Canvas>(cnvsguid0))
            {
                cnvs.RemoveByKey<Canvas>(cnvsguid0);
            }

            #endregion
            
            #region Setup ComboBoxes

            ComboBox cb = new ComboBox();

            cb.Initialize(142D, 57, ContainerType.Grid, 1, 1, 150D, ComboStyles.TypeAheadButCannotSelectOrCopyText, Brushes.Navy, Brushes.LightGray); //set CanContentScroll to false and ScrollViewer Height to 150          
            
            cb.SetCompositeGridDimensions<ComboBox>(2, 1, 93, GridUnitType.Pixel, 25, GridUnitType.Pixel);
            cb.BeginSettings<ComboBox>().SetItemBorderSettings<ComboBox>(90, 50, Brushes.Black, new Thickness(2)).EndSettings<ComboBox>();
            cb.SubscribeEventOnParent<ComboBox, SelectionChangedEventArgs>("SelectionChanged", (cb_SelectionChanged));

            cb.BeginComposite<ComboBox>(cbGuid1).AddText<ComboBox>(0, 0, "Blue").AddText<ComboBox>(1, 0, "Blue as water.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(0, 0));
            cb.BeginComposite<ComboBox>(cbGuid2).AddText<ComboBox>(0, 0, "Red").AddText<ComboBox>(1, 0, "Red as apple.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(0, 0));
            cb.BeginComposite<ComboBox>(cbGuid3).AddText<ComboBox>(0, 0, "Green").AddText<ComboBox>(1, 0, "Green as grass.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(0, 0));
            cb.BeginComposite<ComboBox>(cbGuid4).AddText<ComboBox>(0, 0, "Orange").AddText<ComboBox>(1, 0, "Orange as pumpkin.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(0, 0));
            cb.BeginComposite<ComboBox>(cbGuid5).AddText<ComboBox>(0, 0, "Yellow").AddText<ComboBox>(1, 0, "Yellow as taxicab.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(0, 0));
            cb.BeginComposite<ComboBox>(cbGuid6).AddText<ComboBox>(0, 0, "Purple").AddText<ComboBox>(1, 0, "Purple as grape.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(0, 0));
            cb.BeginComposite<ComboBox>(cbGuid7).AddText<ComboBox>(0, 0, "Brown").AddText<ComboBox>(1, 0, "Brown as dirt.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(0, 0));
            cb.BeginComposite<ComboBox>(cbGuid8).AddText<ComboBox>(0, 0, "Black").AddText<ComboBox>(1, 0, "Black as midnight.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(0, 0));
            cb.BeginComposite<ComboBox>(cbGuid9).AddText<ComboBox>(0, 0, "Silver").AddText<ComboBox>(1, 0, "Silver as lining.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(0, 0));

            cb.SetSelectedKey(cbGuid3);

            ComboBox cb1 = new ComboBox();
            cb1.Initialize(142D, 57, ContainerType.Grid, 1, 1, 150D, ComboStyles.TypeAheadSelectableButAcceptsAnyText, Brushes.DarkGreen, Brushes.Khaki); //set CanContentScroll to false and ScrollViewer Height to 150        
            
           cb1.ApplyComboBoxStrategy("20", "White", "Gold", true, "LawnGreen", "Gold", "Gold", "Black", "Orange", "M 1,4.5  L 4.5,1  L 8,4.5", "Blue", "Red", "Gray");
          //  cb1.ApplyComboBoxStrategy("20", "White", "Gold", true, "LawnGreen", "Gold", "Gold", "Black");

            cb1.ApplyScrollViewerStrategy("LawnGreen", "Green", "ForestGreen");

            cb1.SetCompositeGridDimensions<ComboBox>(2, 1, 93, GridUnitType.Pixel, 25, GridUnitType.Pixel);
            cb1.BeginSettings<ComboBox>().SubscribeEventOnParent<ComboBox, SelectionChangedEventArgs>("SelectionChanged", (cb1_SelectionChanged))
                .SetItemBorderSettings<ComboBox>(90, 50, Brushes.Black, new Thickness(2)).EndSettings<ComboBox>();
           
            //test ability to unsubscribe
            cb1.UnsubscribeSelectionChangedOnParent<ComboBox>();

            //ComboBox cb45 = new ComboBox();
            //cb45.Initialize(142D, 57, ContainerType.Grid, 1, 1, 150D, ComboStyles.TypeAheadSelectableButAcceptsAnyText, Brushes.DarkGreen, Brushes.Khaki); //set CanContentScroll to false and ScrollViewer Height to 150        
            //cb45.SetCompositeGridDimensions<ComboBox>(2, 1, 93, GridUnitType.Pixel, 25, GridUnitType.Pixel);
            //cb45.BeginComposite<ComboBox>(cbGuid1).AddText<ComboBox>(0, 0, "Blue").AddText<ComboBox>(1, 0, "Blue as water.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));
            //cb45.BeginComposite<ComboBox>(cbGuid2).AddText<ComboBox>(0, 0, "Red").AddText<ComboBox>(1, 0, "Red as apple.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

            cb1.BeginComposite<ComboBox>(cbGuid1).AddText<ComboBox>(0, 0, "Blue").AddText<ComboBox>(1, 0, "Blue as water.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));
            cb1.BeginComposite<ComboBox>(cbGuid2).AddText<ComboBox>(0, 0, "Red").AddText<ComboBox>(1, 0, "Red as apple.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));
            cb1.BeginComposite<ComboBox>(cbGuid3).AddText<ComboBox>(0, 0, "Green").AddText<ComboBox>(1, 0, "Green as grass.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));
            cb1.BeginComposite<ComboBox>(cbGuid4).AddText<ComboBox>(0, 0, "Orange").AddText<ComboBox>(1, 0, "Orange as pumpkin.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));
            cb1.BeginComposite<ComboBox>(cbGuid5).AddText<ComboBox>(0, 0, "Yellow").AddText<ComboBox>(1, 0, "Yellow as taxicab.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));
            cb1.BeginComposite<ComboBox>(cbGuid6).AddText<ComboBox>(0, 0, "Purple").AddText<ComboBox>(1, 0, "Purple as grape.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));
            cb1.BeginComposite<ComboBox>(cbGuid7).AddText<ComboBox>(0, 0, "Brown").AddText<ComboBox>(1, 0, "Brown as dirt.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));
            cb1.BeginComposite<ComboBox>(cbGuid8).AddText<ComboBox>(0, 0, "Black").AddText<ComboBox>(1, 0, "Black as midnight.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));
            cb1.BeginComposite<ComboBox>(cbGuid9).AddText<ComboBox>(0, 0, "Silver").AddText<ComboBox>(1, 0, "Silver as lining.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

            cb1.SetSelectedKey(cbGuid3);

            #endregion
            
            #region Setup Multi-Line TextBox with styled ScrollViewer

            TextBox trex = new TextBox(); 
            trex.InitializeForScrollViewerSupport(100D, 150D, 140D);  //TextBox is NOT an IParent but it is an IScrollViewerStrategy.
            ScrollViewerStyle.ApplyToScrollViewer<TextBox>(trex, "PowderBlue", "White", "Blue");
            trex.Text = "This is an example\n of a\n multi-line textbox with enough text in it to trigger the vertical scrollbar to display.";

            #endregion

            int rotateAngle = 30;
            //Now add everything to Cell 1 in the Grid
            thisComposite = myGrid.BeginComposite<Grid>(gridguid1)
                    .ShowGridLinesOnGridComposite<Grid>()
                    //.AddAnything<Label, Grid>(0, 0)
                    .SubscribeEventOnContainer<Grid, Grid, RoutedEventArgs>("GotFocus", (
                     (sender, e) => { MessageBox.Show("GotFocus " + e.Source.ToString()); }))
                    .SubscribeMouseSingleClickOnContainer<Grid, Grid>((o, ev) => { MessageBox.Show("singleclick!"); })
                    .AddLabel<Grid>(0, 0, "1/1/2010", Brushes.White)
                    .AddLabel<Grid>(1, 0, "Attraction:", Brushes.Red)
                    .AddText<Grid>(2, 0, "Location:")
                    .AddText<Grid>(4, 0, "Flight:")
                    .AddText<Grid>(5, 0, "Hotel:")
                    .AddText<Grid>(3, 0, "Parking Garage Color:")
                    .AddText<Grid>(12, 0, "Clickable Geometry:")
                    .AddGeometry<Grid>(13, 0, Brushes.LightSlateGray, new Pen(){ Brush=Brushes.Silver, Thickness=5 }, new EllipseGeometry(){ RadiusX=55, RadiusY=35 }, 70)
                    .SubscribeMouseSingleClickOnChild<Image, Grid>(13, 0, (o, e) => { GeometryExt.GetGeometryFromImage(o).Transform = new RotateTransform() { Angle = rotateAngle }; rotateAngle = rotateAngle + 30; if (rotateAngle == 180) { rotateAngle = 0; } })
                    .AddText<Grid>(14, 0, "Masked TextBox:")
                    .AddText<Grid>(15, 0, "Overlay Text")
                    .AddText<Grid>(5, 3, "Currency (Max $999.99):")
                    .AddText<Grid>(8, 3, "Percent (Max 100.00):")
                    .AddAnything<TextBox, Grid>(1, 1)
                    .AddAnything<TextBox, Grid>(2, 1)
                    .SubscribeEventOnChild<TextBox, Grid, TextChangedEventArgs>(2, 1, "TextChanged", (
                        (sender, e) => { MessageBox.Show("Text Changed Added Length: " + e.Changes.ToList().FirstOrDefault().AddedLength.ToString()); }))
                    .AddExisting<ComboBox, Grid>(3, 1, cb)
                    .AddAnything<TextBox, Grid>(4, 1)
                    .AddAnything<TextBox, Grid>(5, 1)
                    .AddExisting<Border, Grid>(7, 0, borderButton0)
                    .AddExisting<Border, Grid>(7, 1, borderButton)
                    .AddExisting<Border, Grid>(8, 0, borderButton1)
                    .AddExisting<Border, Grid>(8, 1, flatButton)
                    .AddExisting<Border, Grid>(9, 1, flatButton2)
                    .AddExisting<Border, Grid>(10, 1, validateButton)
                    .AddExisting<ComboBox, Grid>(11, 1, cb1)
                    .AddText<Grid>(12, 1, " ")
                //.AddExisting<ComboBox, Grid>(12, 1, cb45).SubscribeEvent<ComboBox, Grid>(12, 1, "SelectionChanged", new SelectionChangedEventHandler((o, e) => { System.Windows.MessageBox.Show("test"); }))
                    .AddAnything<DatePicker, Grid>(13, 1)
                    .AddFixedLengthMaskedTextBox<Grid>(14, 1, "(219) 999-9999", "(000) 000-0000", true, true)
                    .AddNumericTextBox<Grid>(7, 3, 100D, 30D, 299.99M, 999.99M, 0.00M, 1.00M, "C2", true)
                    .ModifyAtXY<wpfToolkit.DecimalUpDown, Grid>(7, 3, de => { de.SetSelectorClass("decimalControl"); })
                    .AddNumericTextBox<Grid>(9, 3, 100D, 30D, .99M, 1.00M, 0.00M, .010M, "P2", true)
                    .AddAnything<wpfToolkit.MultiLineTextEditor, Grid>(10, 3)

                    .AddExisting<TextBox, Grid>(11, 3, trex)
                // .AddExisting<Border, Grid>(9, 1, flatButton2)
                // .SetMouseOverColorOnContainer<Grid, Grid>(Brushes.Silver)
                    .EndComposite<Grid, GridArgs>(new GridArgs(0, 0));

            //  myGrid.UnsubscribeChildEvent<Grid>(gridguid1, 12, 1, "SelectionChanged");

            myGrid.UnsubscribeMouseSingleClickOnContainerByKey(gridguid1);

            //.AddImage<Grid>(gridguid1, 0, 1, @"pack://siteoforigin:,,,/Images/lake.bmp", UriKind.Absolute, Double.NaN, 1, 1)                        
            thisComposite.GetChildFromComposite<TextBox, Grid>(5, 1).Text = "hi!";
            //  MessageBox.Show(thisComposite.IsChildOnComposite<TextBox, Grid>(5, 1).ToString());
            //   System.Windows.MessageBox.Show(thisComposite.GetTextFromFixedLengthMaskedTextBox<Grid>(14, 1));
            //    System.Windows.MessageBox.Show(thisComposite.GetValueFromNumericTextBox<Grid>(7, 3).ToString());
            //    System.Windows.MessageBox.Show(thisComposite.GetValueFromNumericTextBox<Grid>(9, 3).ToString());

            Label lbl1 = myGrid.GetChildFromParent<Label, Grid>(gridguid1, 0, 0);

            lbl1.VerticalAlignment = VerticalAlignment.Center;
            lbl1.BorderBrush = Brushes.Blue;
            lbl1.BorderThickness = new Thickness(0, 0, 0, 2);
            lbl1.Margin = new Thickness(0, 0, 0, 2);
            FontExt.ApplyFontSettings(new FontSettings() { FontFamily = "Tahoma", FontSize = 20D, FontWeight = FontWeights.SemiBold, FontStyle = FontStyles.Normal }, lbl1);

            Border gridBorder = myGrid.GetCompositeFromParent<Grid>(gridguid1);
            gridBorder.Background = Brushes.GhostWhite;
            //.SubscribeAnyEventOnBorder<Grid>(gridguid1, "MouseEnter",
            //new MouseEventHandler((sender, e) =>
            //{
            //    MessageBox.Show("MouseEnter X-position: " + e.GetPosition((IInputElement)sender).X.ToString());
            //}));

            string dPnl2 = Guid.NewGuid().ToString();
            string labelPnl1 = Guid.NewGuid().ToString();

            myDockPanel2.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, 5, 3);
            //  myDockPanel2.SetCompositeGridDimensions<DockPanel>(97.00D, 300.00D, 1, 1, 90.00D, GridUnitType.Pixel, 90.00D, GridUnitType.Pixel);
            myDockPanel2.LastChildFill = true;
            myDockPanel2.Background = Brushes.GhostWhite;

            myDockPanel2.BeginComposite<DockPanel>(dPnl2)
                .AddExisting<ListBox, DockPanel>(0, 0, myListBox)
                .EndComposite<DockPanel, DockArgs>(new DockArgs(Dock.Top));

            string dPnl3 = Guid.NewGuid().ToString();

            myDockPanel3.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, 5, 3);
            //  myDockPanel2.SetCompositeGridDimensions<DockPanel>(97.00D, 300.00D, 1, 1, 90.00D, GridUnitType.Pixel, 90.00D, GridUnitType.Pixel);
            myDockPanel3.LastChildFill = true;
            myDockPanel3.Background = Brushes.GhostWhite;

            myDockPanel3.BeginComposite<DockPanel>(dPnl3)
                .AddExisting<ListView, DockPanel>(0, 0, myListView)
                .EndComposite<DockPanel, DockArgs>(new DockArgs(Dock.Top));


            //Example of older syntax before BeginComposite...EndComposite
            myGrid.AddComposite<Grid, GridArgs>(gridguid2, new GridArgs(0, 1), container =>
            {
                container.AddAnything<Label, Grid>(gridguid2, 0, 0).AddExisting<DockPanel, Grid>(gridguid2, 2, 0, myDockPanel2);
            });

            myGrid.AddComposite<Grid, GridArgs>(gridguid3, new GridArgs(0, 2), container =>
            {
                container.AddAnything<Label, Grid>(gridguid3, 0, 0)
                    .AddText<Grid>(gridguid3, 1, 0, "List View Example - Customize View - Expand All!")
                    .AddText<Grid>(gridguid3, 1, 1, "Collapse All!")
                    .AddExisting<DockPanel, Grid>(gridguid3, 2, 0, myDockPanel3);
            });

            //Customize View for ListView - Expand All
            myGrid.SubscribeEventOnChild<TextBlock, Grid, MouseButtonEventArgs>(gridguid3, 1, 0, "PreviewMouseDown", (ve =>
            {
                myListView.BorderBrush = Brushes.Purple;
                myListView.CustomizeView(bdr => {
                    customizeListView(bdr, true);
                });
            }));
            
            //Customize View for ListView - Collapse All
            myGrid.SubscribeEventOnChild<TextBlock, Grid, MouseButtonEventArgs>(gridguid3, 1, 1, "PreviewMouseDown", (ve =>
            {
                myListView.BorderBrush = Brushes.Purple;
                myListView.CustomizeView(bdr =>
                {
                    customizeListView(bdr, false);
                });
            }));

            Label lblGuid2 = myGrid.GetChildFromParent<Label, Grid>(gridguid2, 0, 0);
            lblGuid2.Content = "3/1/2010";
            lblGuid2.VerticalAlignment = VerticalAlignment.Center;
            lblGuid2.BorderBrush = Brushes.Blue;
            lblGuid2.BorderThickness = new Thickness(0, 0, 0, 2);
            lblGuid2.Margin = new Thickness(0, 0, 0, 2);
            FontExt.ApplyFontSettings(new FontSettings() { FontFamily = "Tahoma", FontSize = 20D, FontWeight = FontWeights.SemiBold, FontStyle = FontStyles.Normal },
            lblGuid2);

            Label lblGuid3 = myGrid.GetChildFromParent<Label, Grid>(gridguid3, 0, 0);
            lblGuid3.Content = "3/3/2010";
            lblGuid3.VerticalAlignment = VerticalAlignment.Center;
            lblGuid3.BorderBrush = Brushes.Blue;
            lblGuid3.BorderThickness = new Thickness(0, 0, 0, 2);
            lblGuid3.Margin = new Thickness(0, 0, 0, 2);
            FontExt.ApplyFontSettings(new FontSettings() { FontFamily = "Tahoma", FontSize = 20D, FontWeight = FontWeights.SemiBold, FontStyle = FontStyles.Normal },
            lblGuid3);

            Border gridBorder2 = myGrid.GetCompositeFromParent<Grid>(gridguid2);
            gridBorder2.Background = Brushes.GhostWhite;

            myGrid.UnsubscribeMouseDoubleClickOnBorderByKey(gridguid2);

            //     myGrid.UnsubscribeAnyEventByKey<Grid>(gridguid1);
            // myGrid.UnsubscribeMouseDoubleClickByKey(gridguid3);

            #region ListBox

            myListBox.Initialize(double.NaN, double.NaN, ContainerType.Grid, 5, 3); //use overload to set width and height to Auto
            myListBox.UseWrapPanel();
            myListBox.Background = Brushes.Red;
       
            // myListBox.UseHorizontalListBox();
            myListBox.SetCompositeGridDimensions<ListBox>(2, 3, 193, GridUnitType.Pixel);

            //MultiBinding mb =  new MultiBinding();// { Bindings =  Path = new PropertyPath("Name") }
            //mb.Bindings.Add(new Binding("Name"));
            //mb.Bindings.Add(new Binding("ItemCount"));
            //GroupLabelConverter glcon = new GroupLabelConverter();
            //mb.Converter = glcon;

            myListBox.BeginSettings<ListBox>()
                //rename to prevent confusion??? This is on Parent right?
                .SetBackgroundColorOnItemsControl(BrushExt.CreateGradientBrush("#DDDDDD", 25, "#33AAFF", 25, 1, 50, 1, 50)) //settings.SetBackgroundColor(Brushes.Wheat)           //chain.SetBackgroundColor(229, 228, 226, 255);
                
                //group on text at 1, 0
                .SetGroupItemConverter(composite =>
                { return (composite.GetChildFromComposite<TextBlock, ListBox>(1, 0)).GetText().ToString(); }) 

                //create the label for the display of groupings (to display Group Name and Item Count)
               .SetGroupItemFrameworkElementFactory(Factory.CreateLabelForGroupItem(54.0D, 234.0D, 17.0D, FontWeights.Bold, new Thickness(5, 0, 0, 0), Brushes.Black, Brushes.AliceBlue, Brushes.Black, new Thickness(1), HorizontalAlignment.Left))

                .SetGroupExpanderFrameworkElementFactory(Factory.CreateExpanderForGroupItem(null, true, Brushes.Blue, new Thickness(0, 0, 0, 1), "White", "White", "Gold", "Gold", "Yellow", "Yellow", "DarkBlue", ExpanderExt.Shape.Ellipse))
                
                //When using GroupExpander handle setting selected Border manually
                .SubscribeMouseSingleClickOnBorder((o, ev) =>
                {
                    manuallySetSelectedColor<ListBox>(o);
                })
                
                .CreateFontStyleKey("mainFont", "Segoe UI", 27D, FontWeights.Bold, FontStyles.Normal)
                .CreateColorStyleKey("mainColor", Brushes.Snow) //143, 121, 100, 255)
                .SetItemBorderColorAndThickness(Brushes.MidnightBlue, new Thickness(0, 0, 1, 0))
                //.SetGridProperties(3, 3, 29, GridUnitType.Pixel, 95, GridUnitType.Pixel, 310, GridUnitType.Pixel)               
                //.SetRowPadding(new Thickness(10, 10, 10, 10))
                //.SetScrollViewerPadding(new Thickness(10, 10, 10, 10))
                .SetImageMargin(0, 0, new Thickness(0, 0, 0, 0))
                .SetImageStretch(0, 0, Stretch.Fill)
                .SetImageHorizontalAlignment(0, 0, HorizontalAlignment.Left)
                .SetTextPadding(0, 1, new Thickness(0, 5, 0, 10))
                .SetTextPadding(0, 2, new Thickness(0, 10, 0, 10))
                .SubscribeMouseDoubleClickOnBorder(my_MouseDoubleClick, item =>
                {
                    return true; // item.GetText<ListBox>(1, 0).Contains("Lake");
                })
             
                //VERTICAL SCROLLBAR
                .SetVerticalScrollBarColor(Brushes.WhiteSmoke)
                .SetVerticalScrollUpButtonColors("White", "Orange", "White", "#0088FF", "#DDDDDD", "0", "Gray", new Thickness(1), "Black", "Orange", "M 0 4 L 7 4 L 3.5 0 Z")
                .SetVerticalPageUpButtonColors("#DDDDDD", "Gray", "Gray", "#DDDDDD") //, "2", "White", new Thickness(3, 3, 3, 3))
                .SetVerticalPageDownButtonColors("#DDDDDD", "#DDDDDD", "Gray", "Gray") //,"5", "Gray", new Thickness(3, 3, 3, 3))
                .SetVerticalScrollDownButtonColors("White", "Orange", "#DDDDDD", "#0088FF", "White", "0", "Gray", new Thickness(1), "Black", "Orange", "M 0 0 L 3.5 4 L 7 0 Z")
                .SetVerticalScrollThumbColors("#0088FF", "#0088FF", "Gray", "#DDDDDD", "1", "1")

                //HORIZONTAL SCROLLBAR
                .SetHorizontalScrollBarColor(Brushes.WhiteSmoke)
                .SetHorizontalScrollRightButtonColors("#BBB", "Blue", "Red", "Red", "Red", "0", "#FFEE", new Thickness(1), "Black", "Orange", "M 0 0 L 4 4 L 0 8 Z")
                .SetHorizontalPageRightButtonColors("#DDDDDD", "#DDDDDD", "Gray", "Gray") //, "#FFEE", "0", new Thickness(0, 0, 0, 0))
                .SetHorizontalPageLeftButtonColors("#DDDDDD", "Gray", "Gray", "#DDDDDD") // , "#FFEE", "0", new Thickness(0, 0, 0, 0))
                .SetHorizontalScrollLeftButtonColors("#BBB", "Blue", "Red", "Red", "Red", "0", "#FFEE", new Thickness(1), "Black", "Orange", "M 4 0 L 4 8 L 0 4 Z")
                .SetHorizontalScrollThumbColors("#0088FF", "#0088FF", "Gray", "#DDDDDD", "1", "1")

                .SetScrollViewerCornerRectangleColor(Brushes.White)
                //.SetFontRangeToColByStyleKey("mainFont", 0, 0, 2)
                .SetFontToRowByStyleKey("mainFont", 1, 0, 2)
                .SetTextColorToRowByStyleKey("mainColor", 1, 0, 2)
                //.SetFont(0, 2, "Segoe UI", 11D, FontWeights.Normal, FontStyles.Italic).SetFont(1, 1, "Segoe UI", 15D, FontWeights.Normal, FontStyles.Normal)
                //.SetTextColor(0, 2, Brushes.Black)
                .SetVerticalAlignment(0, 1, VerticalAlignment.Center)
                .SetHorizontalAlignmentForText(1, 0, TextAlignment.Center)
                .SetVerticalAlignment(0, 2, VerticalAlignment.Center)
                .SetTextWrapping(0, 1, TextWrapping.Wrap)
                .SetTextMaxHeight(0, 1, 50D)
                .SetTextMaxWidth(0, 1, 300D)
                .SetUseLayoutRounding(true)
                .SetHorizontalAlignmentForText(0, 1, TextAlignment.Right)
                //.SetTextVisibility(0,2,Visibility.Hidden)
                //.SetImageVisibility(0,0, Visibility.Collapsed)
                //.SetHorizontalScrollThumbToBeFixedSizeNotProportional()
                //.SetVerticalScrollThumbToBeFixedSizeNotProportional()
                //.SetSelectedContentControlColorGradient("Wheat", 0.0, "BurlyWood", 1.0, 0, 0, 0, 1); //.SetSelectedContentControlColor(Colors.PaleGoldenrod);
                //.SetAlternatingRows(Brushes.Orange, Brushes.Green)
                .SetSelectedContentControlColor(Colors.LightBlue)
                .EndSettings<ListBox>();

            myListBox.SubscribeSelectionChangedOnParent(myListBox_SelectionChanged);

            tList = new List<Tuple<int, string, int>>(); //item1 is the image type, Item2 is the string key, Item3 is the regular counter

            int i = 0;
            Enumerable.Range(0, 100).ToList().ForEach(x => { i = populateTuple(i, x); });

            tList.ForEach(tup =>
            {
                //for textblock add mouseovercolor, mouseover font, clickedcolor(visitedcolor), etc.
                //for image add mouseoverimage and visitedimage?!? Lower-PRIORITY

                //IS the EXTRA StackPanel for HEADER and FOOTER of Child Items? worth it for if we do wrap-panel or canvas?
                string varyText;
                string varyImage;
                varyEveryThirdImage(tup, out varyText, out varyImage);

                if(varyText.Contains("Lake"))
                {
                       Border b1 = myListBox.BeginComposite<ListBox>(tup.Item2)
                          .AddImage<ListBox>(0, 0, varyImage, UriKind.Absolute, Double.NaN, 1, 2)
                      //   .AddLabel(1,2,"yo",Brushes.Blue)
                            .AddText<ListBox>(1, 0, varyText + ": ")
                            .AddText<ListBox>(1, 1, tup.Item3.ToString())
                         //  .DataBindOneChildsPropertyToParents<Image, ListBox>(0, 0, Image.HeightProperty, ListBox.HeightProperty, System.Windows.Data.UpdateSourceTrigger.PropertyChanged, System.Windows.Data.BindingMode.OneWay)

                            .SetMouseOverColorOnContainer<Grid, ListBox>(Brushes.LightCoral)
                            .EndComposite<ListBox, ListBoxArgs>(null);

                     //   b1.DataBindBordersPropertyToParents<ListBox>(Border.WidthProperty, ListBox.WidthProperty, System.Windows.Data.UpdateSourceTrigger.PropertyChanged, System.Windows.Data.BindingMode.OneWay);

                }
                else
                {
                        Border b2 =  myListBox.BeginComposite<ListBox>(tup.Item2)
                            .AddImage<ListBox>(0, 0, varyImage, UriKind.Absolute, Double.NaN, 1, 2)
                            .AddText<ListBox>(1, 0, varyText + ": ")
                            .AddText<ListBox>(1, 1, tup.Item3.ToString())
                            .SetMouseOverColorOnContainer<Grid, ListBox>(Brushes.LightCoral)
                            .EndComposite<ListBox, ListBoxArgs>(null);
                }
            });

            #region Select a first item. When using GroupExpander handle set selected Border manually
            var compLkp = myListBox.GetCompositeLookupDictionary();
            Border starterItem = (compLkp.First<KeyValuePair<string, object>>()).Value as Border;
            myListBox.SelectedItem = ((Border)starterItem);

            Dictionary<string, object> dictStart = myListBox.GetCompositeLookupDictionary();

            foreach (KeyValuePair<string, object> keyval1 in dictStart)
            {
                (keyval1.Value as Border).Background = Brushes.Transparent;
            }

            ((Border)starterItem).Background = Brushes.PowderBlue;
            #endregion
            
            myListBox.Margin = new Thickness(3);
           
            //these have now been added as settings
            myListBox.UpdateTextBlocks<ListBox>(1, 0, txb1 =>
            {
                // txb1.Effect = new System.Windows.Media.Effects.DropShadowEffect();
                txb1.Background = Brushes.Navy;
            });

            //this is equivalent to above except set via a Style rather than directly which may be useful in cases where order of precedence matters?
            myListBox.UpdateViaStyle<TextBlock, ListBox>(1, 0, typeof(TextBlock), TextBlock.BackgroundProperty, Brushes.Navy);

            myListBox.UpdateTextBlocks<ListBox>(1, 1, txb1 =>
            {
                //txb1.Effect = new System.Windows.Media.Effects.DropShadowEffect();
                txb1.Background = Brushes.Gold;
                
            });
            
            #endregion                       

            #region ListView
            
            myListView.Initialize(double.NaN, double.NaN, ContainerType.Grid, 5, 3); //use overload to set width and height to Auto
            myListView.UseWrapPanel();
            myListView.Background = Brushes.Red;
            //StyleExt.SetStyle(myListView, typeof(ListView), ListView.BorderBrushProperty, Brushes.Purple);
            
            // myListView.GetScrollViewer().VerticalScrollBarVisibility = ScrollBarVisibility.Visible;

            // myListView.UseHorizontalListView();
            myListView.SetCompositeGridDimensions<ListView>(2, 3, 193, GridUnitType.Pixel);
            
            myListView.BeginSettings<ListView>()
                //rename to prevent confusion??? This is on Parent right?
                .SetBackgroundColorOnItemsControl(BrushExt.CreateGradientBrush("#DDDDDD", 25, "#33AAFF", 25, 1, 50, 1, 50)) //settings.SetBackgroundColor(Brushes.Wheat)           //chain.SetBackgroundColor(229, 228, 226, 255);
               
                //1 -group on text at 1, 0
                .SetGroupItemConverter(composite =>
                { return (composite.GetChildFromComposite<TextBlock, ListView>(1, 0)).GetText().ToString(); }) 

                //2
               .SetGroupItemFrameworkElementFactory(new FrameworkElementFactory(typeof(Label))
                         .SetProperty(Label.FontWeightProperty, FontWeights.Bold)
                         .SetProperty(Label.MarginProperty, new Thickness(5, 0, 0, 0))
                         .SetProperty(Label.HeightProperty, 54.0D)
                         .SetProperty(Label.WidthProperty, 234.0D)
                         .SetProperty(Label.FontSizeProperty, 17.0)
                         .SetProperty(Label.BackgroundProperty, Brushes.Green)
                         .SetProperty(Label.BorderBrushProperty, Brushes.Black)
                         .SetProperty(Label.BorderThicknessProperty, new Thickness(1))
                         .SetProperty(Label.HorizontalAlignmentProperty, HorizontalAlignment.Left)
                         .SetProperty(Label.ContentProperty, new Binding() { Path = new PropertyPath("Tag"), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Expander), 1) }))

                //3
                .SetGroupExpanderFrameworkElementFactory(new FrameworkElementFactory(typeof(Expander))
                        .SetProperty(Expander.IsExpandedProperty, true)
                        .SetProperty(Expander.BorderBrushProperty, Brushes.Blue)
                        .SetProperty(Expander.TemplateProperty, ExpanderExt.ApplyExpanderStrategyFull("Navy", "Blue", "Blue", "Purple", "Green", "Gold", "Transparent", "M0,0 L0,5 L5,0 z", "M5,5 L0,5 L5,0 z", ExpanderExt.Shape.Rectangle))
                        .SetProperty(Expander.BorderThicknessProperty, new Thickness(0, 0, 0, 1)))

                //When using GroupExpander handle setting selected Border manually
                .SubscribeMouseSingleClickOnBorder((o, ev) =>
                {
                    manuallySetSelectedColor<ListView>(o);
                })

                .SubscribeSelectionChangedOnParent(myListView_SelectionChanged)
                .CreateFontStyleKey("mainFont", "Segoe UI", 27D, FontWeights.Bold, FontStyles.Normal)
                .CreateColorStyleKey("mainColor", Brushes.Snow) //143, 121, 100, 255)
                .SetItemBorderColorAndThickness(Brushes.MidnightBlue, new Thickness(0, 0, 1, 0))
                //.SetGridProperties(3, 3, 29, GridUnitType.Pixel, 95, GridUnitType.Pixel, 310, GridUnitType.Pixel)               
                //.SetRowPadding(new Thickness(10, 10, 10, 10))
                //.SetScrollViewerPadding(new Thickness(10, 10, 10, 10))
                .SetImageMargin(0, 0, new Thickness(0, 0, 0, 0))
                .SetImageStretch(0, 0, Stretch.Fill)
                .SetImageHorizontalAlignment(0, 0, HorizontalAlignment.Left)
                .SetTextPadding(0, 1, new Thickness(0, 5, 0, 10))
                .SetTextPadding(0, 2, new Thickness(0, 10, 0, 10))
                .SubscribeMouseDoubleClickOnBorder(my_MouseDoubleClick, item =>
                {
                    return true; // item.GetText<ListView>(1, 0).Contains("Lake");
                })

                //VERTICAL SCROLLBAR
                .SetVerticalScrollBarColor(Brushes.WhiteSmoke)
                .SetVerticalScrollUpButtonColors("White", "Orange", "White", "#0088FF", "#DDDDDD", "0", "Gray", new Thickness(1), "Black", "Orange", "M 0 4 L 7 4 L 3.5 0 Z")
                .SetVerticalPageUpButtonColors("#DDDDDD", "Gray", "Gray", "#DDDDDD") //, "2", "White", new Thickness(3, 3, 3, 3))
                .SetVerticalPageDownButtonColors("#DDDDDD", "#DDDDDD", "Gray", "Gray") //,"5", "Gray", new Thickness(3, 3, 3, 3))
                .SetVerticalScrollDownButtonColors("White", "Orange", "#DDDDDD", "#0088FF", "White", "0", "Gray", new Thickness(1), "Black", "Orange", "M 0 0 L 3.5 4 L 7 0 Z")
                .SetVerticalScrollThumbColors("#0088FF", "#0088FF", "Gray", "#DDDDDD", "1", "1")

                //HORIZONTAL SCROLLBAR
                .SetHorizontalScrollBarColor(Brushes.WhiteSmoke)
                .SetHorizontalScrollRightButtonColors("#BBB", "Blue", "Red", "Red", "Red", "0", "#FFEE", new Thickness(1), "Black", "Orange", "M 0 0 L 4 4 L 0 8 Z")
                .SetHorizontalPageRightButtonColors("#DDDDDD", "#DDDDDD", "Gray", "Gray") //, "#FFEE", "0", new Thickness(0, 0, 0, 0))
                .SetHorizontalPageLeftButtonColors("#DDDDDD", "Gray", "Gray", "#DDDDDD") // , "#FFEE", "0", new Thickness(0, 0, 0, 0))
                .SetHorizontalScrollLeftButtonColors("#BBB", "Blue", "Red", "Red", "Red", "0", "#FFEE", new Thickness(1), "Black", "Orange", "M 4 0 L 4 8 L 0 4 Z")
                .SetHorizontalScrollThumbColors("#0088FF", "#0088FF", "Gray", "#DDDDDD", "1", "1")

                .SetScrollViewerCornerRectangleColor(Brushes.White)
                //.SetFontRangeToColByStyleKey("mainFont", 0, 0, 2)
                .SetFontToRowByStyleKey("mainFont", 1, 0, 2)
                .SetTextColorToRowByStyleKey("mainColor", 1, 0, 2)
                //.SetFont(0, 2, "Segoe UI", 11D, FontWeights.Normal, FontStyles.Italic).SetFont(1, 1, "Segoe UI", 15D, FontWeights.Normal, FontStyles.Normal)
                //.SetTextColor(0, 2, Brushes.Black)
                .SetVerticalAlignment(0, 1, VerticalAlignment.Center)
                .SetHorizontalAlignmentForText(1, 0, TextAlignment.Center)
                .SetVerticalAlignment(0, 2, VerticalAlignment.Center)
                .SetTextWrapping(0, 1, TextWrapping.Wrap)
                .SetTextMaxHeight(0, 1, 50D)
                .SetTextMaxWidth(0, 1, 300D)
                .SetUseLayoutRounding(true)
                .SetHorizontalAlignmentForText(0, 1, TextAlignment.Right)
                //.SetTextVisibility(0,2,Visibility.Hidden)
                //.SetImageVisibility(0,0, Visibility.Collapsed)
                //.SetHorizontalScrollThumbToBeFixedSizeNotProportional()
                //.SetVerticalScrollThumbToBeFixedSizeNotProportional()
                //.SetSelectedContentControlColorGradient("Wheat", 0.0, "BurlyWood", 1.0, 0, 0, 0, 1); //.SetSelectedContentControlColor(Colors.PaleGoldenrod);
                //.SetAlternatingRows(Brushes.Orange, Brushes.Green)
                .SetSelectedContentControlColor(Colors.LightBlue)
                .EndSettings<ListView>();

            tList = new List<Tuple<int, string, int>>(); //item1 is the image type, Item2 is the string key, Item3 is the regular counter

            int i2 = 0;
            Enumerable.Range(0, 100).ToList().ForEach(x => { i2 = populateTuple(i2, x); });

            tList.ForEach(tup =>
            {
                //for textblock add mouseovercolor, mouseover font, clickedcolor(visitedcolor), etc.
                //for image add mouseoverimage and visitedimage?!? Lower-PRIORITY

                //IS the EXTRA StackPanel for HEADER and FOOTER of Child Items? worth it for if we do wrap-panel or canvas?
                string varyText;
                string varyImage;
                varyEveryThirdImage(tup, out varyText, out varyImage);

                if (varyText.Contains("Lake"))
                {
                    Border b1 = myListView.BeginComposite<ListView>(tup.Item2)
                       .AddImage<ListView>(0, 0, varyImage, UriKind.Absolute, Double.NaN, 1, 2)
                        //   .AddLabel(1,2,"yo",Brushes.Blue)
                         .AddText<ListView>(1, 0, varyText + ": ")
                         .AddText<ListView>(1, 1, tup.Item3.ToString())
                        //  .DataBindOneChildsPropertyToParents<Image, ListView>(0, 0, Image.HeightProperty, ListView.HeightProperty, System.Windows.Data.UpdateSourceTrigger.PropertyChanged, System.Windows.Data.BindingMode.OneWay)

                         .SetMouseOverColorOnContainer<Grid, ListView>(Brushes.LightCoral)
                         .EndComposite<ListView, ListViewArgs>(null);

                    //   b1.DataBindBordersPropertyToParents<ListView>(Border.WidthProperty, ListView.WidthProperty, System.Windows.Data.UpdateSourceTrigger.PropertyChanged, System.Windows.Data.BindingMode.OneWay);

                }
                else
                {
                    Border b2 = myListView.BeginComposite<ListView>(tup.Item2)
                        .AddImage<ListView>(0, 0, varyImage, UriKind.Absolute, Double.NaN, 1, 2)
                        .AddText<ListView>(1, 0, varyText + ": ")
                        .AddText<ListView>(1, 1, tup.Item3.ToString())
                        .SetMouseOverColorOnContainer<Grid, ListView>(Brushes.LightCoral)
                        .EndComposite<ListView, ListViewArgs>(null);
                }
            });

            myListView.Margin = new Thickness(3);
            myListView.BorderThickness = new Thickness(3);

            #region Select a first item. When using GroupExpander handle set selected Border manually
            var compLkp2 = myListView.GetCompositeLookupDictionary();
            Border starterItem2 = (compLkp2.First<KeyValuePair<string, object>>()).Value as Border;
            myListView.SelectedItem = ((Border)starterItem2);

            Dictionary<string, object> dictStart2 = myListView.GetCompositeLookupDictionary();

            foreach (KeyValuePair<string, object> keyval12 in dictStart2)
            {
                (keyval12.Value as Border).Background = Brushes.Transparent;
            }

            ((Border)starterItem2).Background = Brushes.PowderBlue;
            #endregion



            //these have now been added as settings
            myListView.UpdateTextBlocks<ListView>(1, 0, txb1 =>
            {
                // txb1.Effect = new System.Windows.Media.Effects.DropShadowEffect();
                txb1.Background = Brushes.Navy;
            });

            //this is equivalent to above except set via a Style rather than directly which may be useful in cases where order of precedence matters?
            myListView.UpdateViaStyle<TextBlock, ListView>(1, 0, typeof(TextBlock), TextBlock.BackgroundProperty, Brushes.Navy);

            myListView.UpdateTextBlocks<ListView>(1, 1, txb1 =>
            {
                //txb1.Effect = new System.Windows.Media.Effects.DropShadowEffect();
                txb1.Background = Brushes.Gray;
            });

            #endregion  //end of ListView

            this.BeginComposite<UserControl>(_userCtlGuid)
                .AddLabel<UserControl>(0, 0, "Tab Item 1 -  Grid / ListBox Example", Brushes.Blue)
                .AddExisting<Grid, UserControl>(0, 1, myGrid)
                .EndComposite<UserControl, UserControlArgs>(null);

            TextBlock testOverlayingText = myGrid.GetChildViaLookupDictionary<TextBlock, Grid>(gridguid1, 15, 0);
            testOverlayingText.Foreground = Brushes.White;

            Grid.SetColumn(testOverlayingText, 0);
            Grid.SetRow(testOverlayingText, 0);

        //    thisComposite = myGrid.BeginComposite<Grid>(Guid.NewGuid().ToString())
        //       .AddText<Grid>(0, 0, "Overlay Text")
        //       .EndComposite<Grid, GridArgs>(new GridArgs(0, 0));
           
            //Test unsubscribing
            myGrid.UnsubscribeContainerEventByKey<Grid>("GotFocus", gridguid1);

            #region Prototypes

            //1. Create a Prototype
            StackPanel prototype = new StackPanel();
            prototype.Height = Double.NaN;
            prototype.Width = Double.NaN;
            prototype.Background = Brushes.LightBlue;

            GridSettings compositeGridSettings = myGrid.CompositeGridDimensions<Grid>(double.NaN, double.NaN, 1, 3, 0.33, GridUnitType.Star, 100, GridUnitType.Auto);
            
            //2. Create a Constructor Action To Be Run Against Each Generated (Cloned) Element. This is IMPORTANT for Initialization and Settings!
            Action<StackPanel> myConstructor = prot=>{ 
                prot.Initialize(330D, 330D, ContainerType.HorizontalPanel, Orientation.Vertical);
                prot.SubscribeMouseDoubleClickOnParent<StackPanel>((o, ev) => { MessageBox.Show("mouse double click!"); });
                prot.BeginSettings()
                         
                    .Set<Label, StackPanel>(1, 1, "Width", 43D)
                    .Set<Label, StackPanel>(1, 1, "Height", 43D)
                    .Set<Label, StackPanel>(1, 1, "Background", Brushes.Aqua)
                    .Set<Label, StackPanel>(1, 1, "Foreground", Brushes.Black)

                    .Set<Label, StackPanel>(1, 2, "Width", 43D)
                    .Set<Label, StackPanel>(1, 2, "Height", 43D)
                    .Set<Label, StackPanel>(1, 2, "Background", Brushes.LightBlue)
                    .Set<Label, StackPanel>(1, 2, "Foreground", Brushes.Black)

                    .Set<Label, StackPanel>(1, 3, "Width", 43D)
                    .Set<Label, StackPanel>(1, 3, "Height", 43D)
                    .Set<Label, StackPanel>(1, 3, "Background", Brushes.Violet)
                    .Set<Label, StackPanel>(1, 3, "Foreground", Brushes.Black)
                    .EndSettings();
               // prot.UnsubscribeMouseDoubleClickOnParent<StackPanel>();
            };
           
           //3. Generate the Elements Based On the Prototype and Add to GridComposites According to Range Provided
           List<string> keys = Generators.AddComposites(myGrid, 1, 1, 1, 1, 1, 1, prototype, myConstructor, compositeGridSettings);
           List<string> moreKeys = Generators.AddComposites(myGrid, 0, 1, 1, 0, 1, 1, prototype, myConstructor, compositeGridSettings);

           string myGuidHandle = Guid.NewGuid().ToString();
           StackPanel stackpanelAtCell1_1 = myGrid.GetChildViaLookupDictionary<StackPanel, Grid>(moreKeys[1].ToString(), 0, 1);

           #region Add a Composite with 4 Child Labels
           
           //This Generator and subsequent ApplyLoop offers a more dynamic equivalent of Settings and
           //stackpanelAtCell1_1.BeginComposite<StackPanel>().AddAnything<Rectangle, StackPanel>(0, 1).AddAnything<Rectangle, StackPanel>(0, 2).AddAnything<Rectangle, StackPanel>(0, 3).AddAnything<Rectangle, StackPanel>(0, 4).EndComposite<StackPanel, StackPanelArgs>(null);
           //and stackpanelAtCell1_1.GetChildViaLookupDictionary<Label, StackPanel>(myGuidHandle, 1, 1).Content =  . . . ;

           Label prototypeL = new Label();
           prototypeL.Width = 45D;
           prototypeL.Height = 45D;
           
           Action<int, Label> constructorL = (t, lb) => 
           {
               lb.Background = Brushes.SeaShell;
               lb.BorderBrush = Brushes.Black;
               if (t == 1) { lb.Background = Brushes.Coral; }
           };

           string labelKey = Generators.AddChildrenInColumnRange(stackpanelAtCell1_1, 0, 1, 4, prototypeL, constructorL);

           //Add Text to Labels dynamically
           IterHelpers.ApplyLoop(1, 4, (y =>
           {
               stackpanelAtCell1_1.GetChildViaLookupDictionary<Label, StackPanel>(labelKey, 0, y).Content = y.ToString();
           }));

           #endregion

           //Add a Composite with 3 Child Labels
           stackpanelAtCell1_1.BeginComposite<StackPanel>(myGuidHandle).AddAnything<Label, StackPanel>(1, 1).AddAnything<Label, StackPanel>(1, 2).AddAnything<Label, StackPanel>(1, 3).EndComposite<StackPanel, StackPanelArgs>(null);
           stackpanelAtCell1_1.GetChildViaLookupDictionary<Label, StackPanel>(myGuidHandle, 1, 1).Content = "1";
           stackpanelAtCell1_1.GetChildViaLookupDictionary<Label, StackPanel>(myGuidHandle, 1, 2).Content = "2";
           stackpanelAtCell1_1.GetChildViaLookupDictionary<Label, StackPanel>(myGuidHandle, 1, 3).Content = "3";
           
           //Add 5 Composites each with a single Child Rectangle based on the Prototype (varied in color by the index via the Constructor) 
           Rectangle prototypeRectangle = new Rectangle(){ MinHeight = 43D, MinWidth = 43D, Stroke = Brushes.Black };
           Action<int, Rectangle> rectangleConstructor = (f, rect) => { if (f == 0) { rect.Fill = Brushes.Silver; } else { rect.Fill = Brushes.Blue; }  };
           Generators.AddComposites<Rectangle>(stackpanelAtCell1_1, 2, 0, 0, 4, prototypeRectangle, rectangleConstructor, Orientation.Vertical); 
          
           ////1. Create a Prototype
           //Button prototypButton = new Button();

           ////2. Create a Constructor Action To Be Run Against Each Generated (Cloned) Element. This is IMPORTANT for Initialization and Settings!
           //Action<Button> myConstructor2 = prot => { prot.Visibility = Visibility.Visible;  prot.MinHeight = 100D; prot.MinWidth = 100D; prot.BorderBrush = Brushes.Green; prot.BorderThickness = new Thickness(2); prot.Background = Brushes.AliceBlue; prot.HorizontalAlignment = HorizontalAlignment.Left; };
       
           ////3. Generate the Elements Based On the Prototype and Add to GridComposites According to Range Provided
           //List<string> keys2 = Generators.AddComposites<Button>(myGrid, 0, 1, 0, 2, 1, 2, prototypButton, myConstructor2, compositeGridSettings);
           
           ////4. Manipulate Each Individual Element After the Fact, If Desired
           //Button b1 = myGrid.GetChildViaLookupDictionary<Button, Grid>(keys2[0].ToString(), 0, 1);
           //b1.Content = "1";
           //Button b2 = myGrid.GetChildViaLookupDictionary<Button, Grid>(keys2[1].ToString(), 0, 1);
           //b2.Content = "2";

           #region Add Labels and Fields - Generator Test

           string testGen = Guid.NewGuid().ToString();
           GroupBox grbx = new GroupBox();
           grbx.Margin = new Thickness(4);
           grbx.Padding = new Thickness(4);
           Factory.CreateGroupBoxHeader(grbx, "Test Generator", Brushes.Navy, Brushes.White, "Segoe UI", 12D, FontWeights.SemiBold, FontStyles.Normal, Brushes.Navy, new Thickness(2));
            
           grbx.Initialize(300D, 300D, ContainerType.ContentControlPanel);
           Label lbl2 = new Label();
           Label lbl3 = new Label();
           myGrid.BeginComposite<Grid>(testGen).AddExisting<Label, Grid>(0, 0, lbl2).AddExisting<Label, Grid>(1, 0, lbl3).AddExisting<GroupBox, Grid>(2, 0, grbx).EndComposite<Grid, GridArgs>(new GridArgs(1, 2));
           //.SubscribeMouseSingleClickOnChild<GroupBox, Grid>(2, 0, (o, ev) => { MessageBox.Show("Hey! You clicked on the GroupBox."); })

           //override content that was set via settings 
           myGrid.GetChildFromParent<Label, Grid>(testGen, 0, 0).Content= "1/1/2010";
           myGrid.GetChildFromParent<Label, Grid>(testGen, 1, 0).Content = "Aa1 - to test sorting";
            //Prototype Label
           Label lblPrototype = new Label();
           lblPrototype.Width = 115D;
           lblPrototype.Height = 39D;
           lblPrototype.Margin = new Thickness(17, 5, 7, 5);
           lblPrototype.Background = Brushes.CornflowerBlue; 
           lblPrototype.Foreground = Brushes.White;
           Action<int, Label> actLbl = (j, lbl) => { 
               //vary the 4th one
               if (j == 4) { lbl.Background = Brushes.Silver; } 
           };

         // myGrid.UnsubscribeMouseSingleClickOnChild<Grid>(testGen, 0, 1);

           //Prototype TextBox
           TextBox txtBoxPrototype = new TextBox();
           txtBoxPrototype.Width = 150D;
           txtBoxPrototype.Height = 39D;
           txtBoxPrototype.Margin = new Thickness(7, 5, 7, 5);
           txtBoxPrototype.Background = BrushExt.CreateGeometryBrush(Brushes.LightYellow, new Pen(){ Brush=Brushes.Silver, Thickness=.3 }, new RectangleGeometry(new Rect(1, 1, .9, .7)));
           Action<int, TextBox> actTxtBox = (z, txtBx) =>
           {    //vary the 1st one
               if (z == 0) { txtBx.Text = "3 sample text";  }
               if (z == 1) { txtBx.Text = "2"; }
               if (z == 2) { txtBx.Text = "1"; }  
           };
            
           List<string> labelCaptions = new List<string>();
           labelCaptions.Add("Label 1");
           labelCaptions.Add("Label 1");
           labelCaptions.Add("Long Label 2");
           labelCaptions.Add("Label 4");
           labelCaptions.Add("Label 5");

           List<string> grbxKeys = Generators.AddLabelsAndFields(grbx, labelCaptions, 0, 0, 4, 41D, lblPrototype, actLbl, txtBoxPrototype, actTxtBox);
           
           #endregion

           #endregion

           isLoading = false;
        }

        private void customizeListView(Border bdr, bool isExpanded)
        {
            string z = bdr.GetKey();
            myListView.GetImage<ListView>(z, 0, 0).Visibility = Visibility.Collapsed;
            myListView.GetTextBlock<ListView>(z, 1, 0).Background = Brushes.LightSalmon;
            bdr.BorderThickness = new Thickness(5);
            bdr.BorderBrush = Brushes.DarkGoldenrod;

            #region Add new group label style

            //step 1
            FrameworkElementFactory factoryLabel = Factory.CreateLabelForGroupItem(34.0D, 334.0D, 17.0D, FontWeights.Bold, new Thickness(5, 0, 0, 0), Brushes.Orange, Brushes.AliceBlue, Brushes.Red, new Thickness(1), HorizontalAlignment.Left);

            //step 2
            FrameworkElementFactory factoryExpander = Factory.CreateExpanderForGroupItem(factoryLabel, isExpanded, Brushes.Green, new Thickness(0, 0, 0, 1), "Orange", "Red", "Blue", "Purple", "Green", "Gold", "Transparent", "M0,0 L0,5 L5,0 z", "M5,5 L0,5 L5,0 z", ExpanderExt.Shape.Rectangle);

            //step 3
            Style myStyle = Factory.CreateStyleForGroupItem(factoryExpander, new Thickness(1));

            //step 4
            GroupStyle groupStyle = new GroupStyle();
            groupStyle.ContainerStyle = myStyle;
            myListView.GroupStyle.Clear();
            myListView.GroupStyle.Add(groupStyle);

            #endregion

            myListView.SetVerticalScrollThumbColors<ListView>("Orange", "Silver", "Gray", "Orange", "0", "0");

            //bdr.SubscribeEventOnBorder<ListView>(bdr.GetKey(),  "PreviewMouseLeftButtonDown", new MouseButtonEventHandler(bdr_PreviewMouseDown));
            //myListView.SubscribeSelectionChangedOnParent(myListView_SelectionChanged);
        }

        private static void manuallySetSelectedColor<T>(object o)
            where T: ListBox
        {
            var cc1 = ((Border)o).Child as ContentControl;
            var lv1 = cc1.Tag as T;
            lv1.SelectedItem = ((Border)o);

            Dictionary<string, object> dict = lv1.GetCompositeLookupDictionary();

            foreach (KeyValuePair<string, object> keyval in dict)
            {
                (keyval.Value as Border).Background = Brushes.Transparent;
            }

            ((Border)o).Background = Brushes.PowderBlue;
        }

        //void bdr_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        //{

        //}

        private void createEnabledButtonComposite(Grid myGrid, string borderButton0Guid, Border borderButton0, string transferData)
        {

            IDisposable dispB0 = null;
            borderButton0.SubscribeMouseSingleClickOnBorder<Border>((o, ev) =>
            {
                //in lieu of Color Animation, consider Rx . . .
                BorderExt.ChangeBackgroundColor(borderButton0, Brushes.Khaki);
                BorderExt.SetMouseOverColorOnBorder(borderButton0, Brushes.Khaki);

                //Display Khaki for 3 seconds, then revert to PowderBlue
                dispB0 = Observable.Timer(TimeSpan.FromSeconds(3)).Subscribe(t =>
                {
                    Dispatcher.RunInUiThread(() =>
                    {

                        BorderExt.ChangeBackgroundColor(borderButton0, Brushes.PowderBlue);
                        BorderExt.SetMouseOverColorOnBorder(borderButton0, Brushes.Orange);
                    });
                });

                GridSort gs = new GridSort(CommonExt.SortDataType.DateTime, CommonExt.SortDataType.String);
                //myGrid.SortByText<Grid>(gs, 0, 0, CommonExt.SortOrder.Asc, CommonExt.SortControlType.Label);
                myGrid.SortByText1AndThenBy2<Grid>(gs, 0, 0, 1, 0, CommonExt.SortOrder.Asc, CommonExt.SortOrder.Desc, CommonExt.SortControlType.Label);

            });

            borderButton0.SetMouseOverColorOnBorder(Brushes.Orange);

            borderButton0.BeginComposite(borderButton0Guid)
                .AddText<Border>(0, 0, transferData??"Sort Grid Asc 1 then 2")
                .EndComposite<Border, BorderArgs>(null);
        }
        
        #region Helper methods for populating elements

        private void varyEveryThirdImage(Tuple<int, string, int> tup, out string varyText, out string varyImage)
        {
            if (tup.Item3 == 1)
            {
                twoGUID = tup.Item2;
            }

            int y = tup.Item1;
            varyText = String.Empty;
            varyImage = String.Empty;
            if (y == 0)
            {
                varyText = " Lake #";
                varyImage = @"pack://siteoforigin:,,,/Images/lake.bmp";
            }

            if (y == 1)
            {
                varyText = " Woods #";
                varyImage = @"pack://siteoforigin:,,,/Images/woods.bmp";   // @"/FasterWPFDemo;component/Images/woods.bmp";
            }

            if (y == 2)
            {
                varyText = " Desert #";
                varyImage = @"pack://siteoforigin:,,,/Images/desert.bmp";
            }
        }

        private int populateTuple(int i, int x)
        {
            int j = i;

            tList.Add(new Tuple<int, string, int>(j, Guid.NewGuid().ToString(), x));

            if (i < 2)
            {
                i++;
            }
            else
            {
                i = 0; //reset
            }
            return i;
        }


        #endregion

    }
}
